//
//  JYJDownLoadCollectionViewCell.m
//  HappyListen
//
//  Created by 冀永金 on 16/9/20.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "JYJDownLoadCollectionViewCell.h"
#import "BaseTableView.h"
#import "JYJDownLoadTableViewCell.h"
#import "JYJProgramModel.h"
#import "UIImageView+WebCache.h"
#import "JYJProgramListModel.h"
#import "JYJTAMacro.h"
#import "BaseLabel.h"
#import "JYJMusicPlayerViewController.h"
@interface JYJDownLoadCollectionViewCell ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) BaseTableView *tableview;

@end
@implementation JYJDownLoadCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        self.tableview = [[BaseTableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        [self.contentView addSubview:_tableview];
        self.tableview.delegate = self;
        self.tableview.dataSource = self;
        [self.tableview registerClass:[JYJDownLoadTableViewCell class] forCellReuseIdentifier:@"pool"];
         self.tableview.backgroundColor = [UIColor colorWithRed:0.07 green:0.07 blue:0.08 alpha:1.00];
        self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return self;
}
- (void)setMarr:(NSMutableArray *)marr {
    _marr = marr;
    if (marr.count == 0) {
       
    }else {
    
        [self.tableview reloadData];
    
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.tableview.frame = self.contentView.bounds;
   
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.marr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    JYJDownLoadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool" forIndexPath:indexPath];
    JYJProgramModel *model = self.marr[indexPath.row];
    [cell.musicImage sd_setImageWithURL:[NSURL URLWithString:model.music_img] placeholderImage:PLACEHOLDERIMAGE];
    cell.titleLabel.text = model.music_title;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 110;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   JYJProgramModel *model = self.marr[indexPath.row];
       JYJMusicPlayerViewController *music = [JYJMusicPlayerViewController shareMusicPlayerVC];
    music.programModel = model;
    music.modelIndex = indexPath.row;
       self.handleAction (music);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
